﻿//**************************************************
//CLASS : tcdc_trn_payment_info
//AUTHOR : PATTARAWUT CHANNGAM & SUCHIN INPIRUT
//LAST MODIFIED : Monday, February 25, 2013
//**************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Model
{

public class tcdc_trn_payment_info
{

     private DBUtil DB;
     public string strConn { get; set; }
     public int payment_info_id {get;set;}
     public string invoice_no {get;set;}
     public string payment_date {get;set;}
     public int user_id {get;set;}
     public string payment_name {get;set;}
     public string payment_address {get;set;}
     public string province {get;set;}
     public string post_code {get;set;}
     public string payment_method {get;set;}
     public string bank_name {get;set;}
     public string bank_branch {get;set;}
     public int budget_year {get;set;}
     public int payment_no {get;set;}
     public string cancel_status {get;set;}
     public string cancel_desc {get;set;}
     public string create_date {get;set;}
     public int create_by {get;set;}
     public string update_date {get;set;}
     public int update_by {get;set;}
     public int site_id {get;set;}

     public tcdc_trn_payment_info() {
          this.DB = new DBUtil();
          DB.strConn = strConn;
     }

     public DataTable getById(string id) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_trn_payment_info" + 
                       " WHERE payment_info_id = '" + id + "'";

          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public DataTable getByObject(tcdc_trn_payment_info obj) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_trn_payment_info " + 
                       "WHERE 1 = 1 ";

          if(obj.payment_info_id != null && 
             obj.payment_info_id.ToString() != null && 
             obj.payment_info_id.ToString() != "0")
          {
               sql += "AND payment_info_id LIKE '%" + obj.payment_info_id + "%' ";
          }
          if(obj.invoice_no != null && 
             obj.invoice_no.ToString() != null && 
             obj.invoice_no.ToString() != "0")
          {
               sql += "AND invoice_no LIKE '%" + obj.invoice_no + "%' ";
          }
          if(obj.payment_date != null && 
             obj.payment_date.ToString() != null && 
             obj.payment_date.ToString() != "0")
          {
               sql += "AND payment_date LIKE '%" + obj.payment_date + "%' ";
          }
          if(obj.user_id != null && 
             obj.user_id.ToString() != null && 
             obj.user_id.ToString() != "0")
          {
               sql += "AND user_id LIKE '%" + obj.user_id + "%' ";
          }
          if(obj.payment_name != null && 
             obj.payment_name.ToString() != null && 
             obj.payment_name.ToString() != "0")
          {
               sql += "AND payment_name LIKE '%" + obj.payment_name + "%' ";
          }
          if(obj.payment_address != null && 
             obj.payment_address.ToString() != null && 
             obj.payment_address.ToString() != "0")
          {
               sql += "AND payment_address LIKE '%" + obj.payment_address + "%' ";
          }
          if(obj.province != null && 
             obj.province.ToString() != null && 
             obj.province.ToString() != "0")
          {
               sql += "AND province LIKE '%" + obj.province + "%' ";
          }
          if(obj.post_code != null && 
             obj.post_code.ToString() != null && 
             obj.post_code.ToString() != "0")
          {
               sql += "AND post_code LIKE '%" + obj.post_code + "%' ";
          }
          if(obj.payment_method != null && 
             obj.payment_method.ToString() != null && 
             obj.payment_method.ToString() != "0")
          {
               sql += "AND payment_method LIKE '%" + obj.payment_method + "%' ";
          }
          if(obj.bank_name != null && 
             obj.bank_name.ToString() != null && 
             obj.bank_name.ToString() != "0")
          {
               sql += "AND bank_name LIKE '%" + obj.bank_name + "%' ";
          }
          if(obj.bank_branch != null && 
             obj.bank_branch.ToString() != null && 
             obj.bank_branch.ToString() != "0")
          {
               sql += "AND bank_branch LIKE '%" + obj.bank_branch + "%' ";
          }
          if(obj.budget_year != null && 
             obj.budget_year.ToString() != null && 
             obj.budget_year.ToString() != "0")
          {
               sql += "AND budget_year LIKE '%" + obj.budget_year + "%' ";
          }
          if(obj.payment_no != null && 
             obj.payment_no.ToString() != null && 
             obj.payment_no.ToString() != "0")
          {
               sql += "AND payment_no LIKE '%" + obj.payment_no + "%' ";
          }
          if(obj.cancel_status != null && 
             obj.cancel_status.ToString() != null && 
             obj.cancel_status.ToString() != "0")
          {
               sql += "AND cancel_status LIKE '%" + obj.cancel_status + "%' ";
          }
          if(obj.cancel_desc != null && 
             obj.cancel_desc.ToString() != null && 
             obj.cancel_desc.ToString() != "0")
          {
               sql += "AND cancel_desc LIKE '%" + obj.cancel_desc + "%' ";
          }
          if(obj.create_date != null && 
             obj.create_date.ToString() != null && 
             obj.create_date.ToString() != "0")
          {
               sql += "AND create_date LIKE '%" + obj.create_date + "%' ";
          }
          if(obj.create_by != null && 
             obj.create_by.ToString() != null && 
             obj.create_by.ToString() != "0")
          {
               sql += "AND create_by LIKE '%" + obj.create_by + "%' ";
          }
          if(obj.update_date != null && 
             obj.update_date.ToString() != null && 
             obj.update_date.ToString() != "0")
          {
               sql += "AND update_date LIKE '%" + obj.update_date + "%' ";
          }
          if(obj.update_by != null && 
             obj.update_by.ToString() != null && 
             obj.update_by.ToString() != "0")
          {
               sql += "AND update_by LIKE '%" + obj.update_by + "%' ";
          }
          if(obj.site_id != null && 
             obj.site_id.ToString() != null && 
             obj.site_id.ToString() != "0")
          {
               sql += "AND site_id LIKE '%" + obj.site_id + "%' ";
          }
          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public int insertData(tcdc_trn_payment_info obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[20];

          prm[0] = new SqlParameter("@invoice_no", SqlDbType.NVarChar,50);
          if(obj.invoice_no != null && 
             obj.invoice_no.ToString() != null && 
             obj.invoice_no.ToString() != "0")
          {
               prm[0].Value = obj.invoice_no;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }

          prm[1] = new SqlParameter("@payment_date", SqlDbType.DateTime);
          if(obj.payment_date != null && 
             obj.payment_date.ToString() != null && 
             obj.payment_date.ToString() != "0")
          {
               prm[1].Value = obj.payment_date;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }

          prm[2] = new SqlParameter("@user_id", SqlDbType.Int);
          if(obj.user_id != null && 
             obj.user_id.ToString() != null && 
             obj.user_id.ToString() != "0")
          {
               prm[2].Value = obj.user_id;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }

          prm[3] = new SqlParameter("@payment_name", SqlDbType.NVarChar,250);
          if(obj.payment_name != null && 
             obj.payment_name.ToString() != null && 
             obj.payment_name.ToString() != "0")
          {
               prm[3].Value = obj.payment_name;
          }
          else
          {
               prm[3].Value = DBNull.Value;
          }

          prm[4] = new SqlParameter("@payment_address", SqlDbType.NVarChar,250);
          if(obj.payment_address != null && 
             obj.payment_address.ToString() != null && 
             obj.payment_address.ToString() != "0")
          {
               prm[4].Value = obj.payment_address;
          }
          else
          {
               prm[4].Value = DBNull.Value;
          }

          prm[5] = new SqlParameter("@province", SqlDbType.NVarChar,50);
          if(obj.province != null && 
             obj.province.ToString() != null && 
             obj.province.ToString() != "0")
          {
               prm[5].Value = obj.province;
          }
          else
          {
               prm[5].Value = DBNull.Value;
          }

          prm[6] = new SqlParameter("@post_code", SqlDbType.NVarChar,50);
          if(obj.post_code != null && 
             obj.post_code.ToString() != null && 
             obj.post_code.ToString() != "0")
          {
               prm[6].Value = obj.post_code;
          }
          else
          {
               prm[6].Value = DBNull.Value;
          }

          prm[7] = new SqlParameter("@payment_method", SqlDbType.NVarChar,50);
          if(obj.payment_method != null && 
             obj.payment_method.ToString() != null && 
             obj.payment_method.ToString() != "0")
          {
               prm[7].Value = obj.payment_method;
          }
          else
          {
               prm[7].Value = DBNull.Value;
          }

          prm[8] = new SqlParameter("@bank_name", SqlDbType.NVarChar,50);
          if(obj.bank_name != null && 
             obj.bank_name.ToString() != null && 
             obj.bank_name.ToString() != "0")
          {
               prm[8].Value = obj.bank_name;
          }
          else
          {
               prm[8].Value = DBNull.Value;
          }

          prm[9] = new SqlParameter("@bank_branch", SqlDbType.NVarChar,50);
          if(obj.bank_branch != null && 
             obj.bank_branch.ToString() != null && 
             obj.bank_branch.ToString() != "0")
          {
               prm[9].Value = obj.bank_branch;
          }
          else
          {
               prm[9].Value = DBNull.Value;
          }

          prm[10] = new SqlParameter("@budget_year", SqlDbType.Int);
          if(obj.budget_year != null && 
             obj.budget_year.ToString() != null && 
             obj.budget_year.ToString() != "0")
          {
               prm[10].Value = obj.budget_year;
          }
          else
          {
               prm[10].Value = DBNull.Value;
          }

          prm[11] = new SqlParameter("@payment_no", SqlDbType.Int);
          if(obj.payment_no != null && 
             obj.payment_no.ToString() != null && 
             obj.payment_no.ToString() != "0")
          {
               prm[11].Value = obj.payment_no;
          }
          else
          {
               prm[11].Value = DBNull.Value;
          }

          prm[12] = new SqlParameter("@cancel_status", SqlDbType.NVarChar,50);
          if(obj.cancel_status != null && 
             obj.cancel_status.ToString() != null && 
             obj.cancel_status.ToString() != "0")
          {
               prm[12].Value = obj.cancel_status;
          }
          else
          {
               prm[12].Value = DBNull.Value;
          }

          prm[13] = new SqlParameter("@cancel_desc", SqlDbType.NVarChar,250);
          if(obj.cancel_desc != null && 
             obj.cancel_desc.ToString() != null && 
             obj.cancel_desc.ToString() != "0")
          {
               prm[13].Value = obj.cancel_desc;
          }
          else
          {
               prm[13].Value = DBNull.Value;
          }

          prm[14] = new SqlParameter("@create_date", SqlDbType.DateTime);
          if(obj.create_date != null && 
             obj.create_date.ToString() != null && 
             obj.create_date.ToString() != "0")
          {
               prm[14].Value = obj.create_date;
          }
          else
          {
               prm[14].Value = DBNull.Value;
          }

          prm[15] = new SqlParameter("@create_by", SqlDbType.Int);
          if(obj.create_by != null && 
             obj.create_by.ToString() != null && 
             obj.create_by.ToString() != "0")
          {
               prm[15].Value = obj.create_by;
          }
          else
          {
               prm[15].Value = DBNull.Value;
          }

          prm[16] = new SqlParameter("@update_date", SqlDbType.DateTime);
          if(obj.update_date != null && 
             obj.update_date.ToString() != null && 
             obj.update_date.ToString() != "0")
          {
               prm[16].Value = obj.update_date;
          }
          else
          {
               prm[16].Value = DBNull.Value;
          }

          prm[17] = new SqlParameter("@update_by", SqlDbType.Int);
          if(obj.update_by != null && 
             obj.update_by.ToString() != null && 
             obj.update_by.ToString() != "0")
          {
               prm[17].Value = obj.update_by;
          }
          else
          {
               prm[17].Value = DBNull.Value;
          }

          prm[18] = new SqlParameter("@site_id", SqlDbType.Int);
          if(obj.site_id != null && 
             obj.site_id.ToString() != null && 
             obj.site_id.ToString() != "0")
          {
               prm[18].Value = obj.site_id;
          }
          else
          {
               prm[18].Value = DBNull.Value;
          }

          prm[19] = new SqlParameter("@ReturnValue", SqlDbType.Int);
          prm[19].Direction = ParameterDirection.Output;

          DB.ExecuteNonQueryProc("sp_tcdc_trn_payment_info_insert", prm, false);
          return (Int32)prm[19].Value;
     }

     public int updateData(tcdc_trn_payment_info obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[20];

          prm[0] = new SqlParameter("@payment_info_id", SqlDbType.Int);
          if(obj.payment_info_id != null && 
             obj.payment_info_id.ToString() != null && 
             obj.payment_info_id.ToString() != "0")
          {
               prm[0].Value = obj.payment_info_id;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }
          prm[1] = new SqlParameter("@invoice_no", SqlDbType.NVarChar,50);
          if(obj.invoice_no != null && 
             obj.invoice_no.ToString() != null && 
             obj.invoice_no.ToString() != "0")
          {
               prm[1].Value = obj.invoice_no;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }
          prm[2] = new SqlParameter("@payment_date", SqlDbType.DateTime);
          if(obj.payment_date != null && 
             obj.payment_date.ToString() != null && 
             obj.payment_date.ToString() != "0")
          {
               prm[2].Value = obj.payment_date;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }
          prm[3] = new SqlParameter("@user_id", SqlDbType.Int);
          if(obj.user_id != null && 
             obj.user_id.ToString() != null && 
             obj.user_id.ToString() != "0")
          {
               prm[3].Value = obj.user_id;
          }
          else
          {
               prm[3].Value = DBNull.Value;
          }
          prm[4] = new SqlParameter("@payment_name", SqlDbType.NVarChar,250);
          if(obj.payment_name != null && 
             obj.payment_name.ToString() != null && 
             obj.payment_name.ToString() != "0")
          {
               prm[4].Value = obj.payment_name;
          }
          else
          {
               prm[4].Value = DBNull.Value;
          }
          prm[5] = new SqlParameter("@payment_address", SqlDbType.NVarChar,250);
          if(obj.payment_address != null && 
             obj.payment_address.ToString() != null && 
             obj.payment_address.ToString() != "0")
          {
               prm[5].Value = obj.payment_address;
          }
          else
          {
               prm[5].Value = DBNull.Value;
          }
          prm[6] = new SqlParameter("@province", SqlDbType.NVarChar,50);
          if(obj.province != null && 
             obj.province.ToString() != null && 
             obj.province.ToString() != "0")
          {
               prm[6].Value = obj.province;
          }
          else
          {
               prm[6].Value = DBNull.Value;
          }
          prm[7] = new SqlParameter("@post_code", SqlDbType.NVarChar,50);
          if(obj.post_code != null && 
             obj.post_code.ToString() != null && 
             obj.post_code.ToString() != "0")
          {
               prm[7].Value = obj.post_code;
          }
          else
          {
               prm[7].Value = DBNull.Value;
          }
          prm[8] = new SqlParameter("@payment_method", SqlDbType.NVarChar,50);
          if(obj.payment_method != null && 
             obj.payment_method.ToString() != null && 
             obj.payment_method.ToString() != "0")
          {
               prm[8].Value = obj.payment_method;
          }
          else
          {
               prm[8].Value = DBNull.Value;
          }
          prm[9] = new SqlParameter("@bank_name", SqlDbType.NVarChar,50);
          if(obj.bank_name != null && 
             obj.bank_name.ToString() != null && 
             obj.bank_name.ToString() != "0")
          {
               prm[9].Value = obj.bank_name;
          }
          else
          {
               prm[9].Value = DBNull.Value;
          }
          prm[10] = new SqlParameter("@bank_branch", SqlDbType.NVarChar,50);
          if(obj.bank_branch != null && 
             obj.bank_branch.ToString() != null && 
             obj.bank_branch.ToString() != "0")
          {
               prm[10].Value = obj.bank_branch;
          }
          else
          {
               prm[10].Value = DBNull.Value;
          }
          prm[11] = new SqlParameter("@budget_year", SqlDbType.Int);
          if(obj.budget_year != null && 
             obj.budget_year.ToString() != null && 
             obj.budget_year.ToString() != "0")
          {
               prm[11].Value = obj.budget_year;
          }
          else
          {
               prm[11].Value = DBNull.Value;
          }
          prm[12] = new SqlParameter("@payment_no", SqlDbType.Int);
          if(obj.payment_no != null && 
             obj.payment_no.ToString() != null && 
             obj.payment_no.ToString() != "0")
          {
               prm[12].Value = obj.payment_no;
          }
          else
          {
               prm[12].Value = DBNull.Value;
          }
          prm[13] = new SqlParameter("@cancel_status", SqlDbType.NVarChar,50);
          if(obj.cancel_status != null && 
             obj.cancel_status.ToString() != null && 
             obj.cancel_status.ToString() != "0")
          {
               prm[13].Value = obj.cancel_status;
          }
          else
          {
               prm[13].Value = DBNull.Value;
          }
          prm[14] = new SqlParameter("@cancel_desc", SqlDbType.NVarChar,250);
          if(obj.cancel_desc != null && 
             obj.cancel_desc.ToString() != null && 
             obj.cancel_desc.ToString() != "0")
          {
               prm[14].Value = obj.cancel_desc;
          }
          else
          {
               prm[14].Value = DBNull.Value;
          }
          prm[15] = new SqlParameter("@create_date", SqlDbType.DateTime);
          if(obj.create_date != null && 
             obj.create_date.ToString() != null && 
             obj.create_date.ToString() != "0")
          {
               prm[15].Value = obj.create_date;
          }
          else
          {
               prm[15].Value = DBNull.Value;
          }
          prm[16] = new SqlParameter("@create_by", SqlDbType.Int);
          if(obj.create_by != null && 
             obj.create_by.ToString() != null && 
             obj.create_by.ToString() != "0")
          {
               prm[16].Value = obj.create_by;
          }
          else
          {
               prm[16].Value = DBNull.Value;
          }
          prm[17] = new SqlParameter("@update_date", SqlDbType.DateTime);
          if(obj.update_date != null && 
             obj.update_date.ToString() != null && 
             obj.update_date.ToString() != "0")
          {
               prm[17].Value = obj.update_date;
          }
          else
          {
               prm[17].Value = DBNull.Value;
          }
          prm[18] = new SqlParameter("@update_by", SqlDbType.Int);
          if(obj.update_by != null && 
             obj.update_by.ToString() != null && 
             obj.update_by.ToString() != "0")
          {
               prm[18].Value = obj.update_by;
          }
          else
          {
               prm[18].Value = DBNull.Value;
          }
          prm[19] = new SqlParameter("@site_id", SqlDbType.Int);
          if(obj.site_id != null && 
             obj.site_id.ToString() != null && 
             obj.site_id.ToString() != "0")
          {
               prm[19].Value = obj.site_id;
          }
          else
          {
               prm[19].Value = DBNull.Value;
          }

          return DB.ExecuteNonQueryProc("sp_tcdc_trn_payment_info_update", prm, false);
     }

     public int deleteData(string id) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[1];

          prm[0] = new SqlParameter("@payment_info_id", id);

          return DB.ExecuteNonQueryProc("sp_tcdc_trn_payment_info_delete", prm, false);
     }
}

}

